		jQuery(function($) {
				var myTable = 
				$('#dynamic-table')
				.DataTable({
					
					"processing":true,
					"serverSide":true,
					
					"ajax":{
						type:'post',
						url:'?r=purchase/supplierlist',
					},
					 "order": [[ 1, "desc" ]],//默认排序
					 //禁用排序
					"columnDefs":[
					   {"orderable":false,"targets":[0,0]},
					   {"orderable":false,"targets":[0,3]},
					   {"orderable":false,"targets":[0,7]},
					   {"orderable":false,"targets":[0,8]},
					   {"orderable":false,"targets":[0,9]},
					   {"orderable":false,"targets":[0,11]},
					],
					
					"columns": [	
							{ "data": "chose" },
				            { "data": "id" },
				            { "data": "supplierid" },
				            { "data": "suppliername" },
				            { "data": "supplierab" },		          
				            { "data": "address" },
				            { "data": "linkname" },
				            { "data": "linktel" },
				            { "data": "qq" },
				            { "data": "email" },
				            { "data": "state" },
				            { "data": "options" },
				     ],
						    
					//语言国际化
			        language: {
			            url: 'aceAsset/i18n/zh_cn.json'
			        },
					
				});
			
				
				
				$.fn.dataTable.Buttons.swfPath = "aceAsset/js/dataTables/extensions/buttons/swf/flashExport.swf"; //in Ace demo aceAsset will be replaced by correct assets path
				$.fn.dataTable.Buttons.defaults.dom.container.className = 'dt-buttons btn-overlap btn-group btn-overlap';
				
				new $.fn.dataTable.Buttons( myTable, {
					buttons: [
					  {
						"extend": "colvis",
						"text": "<i class='fa fa-search bigger-110 blue'></i> <span class='hidden'>Show/hide columns</span>",
						"className": "btn btn-white btn-primary btn-bold",
						columns: ':not(:first):not(:last)'
					  },
					  {
						"extend": "copy",
						"text": "<i class='fa fa-copy bigger-110 pink'></i> <span class='hidden'>Copy to clipboard</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "csv",
						"text": "<i class='fa fa-database bigger-110 orange'></i> <span class='hidden'>Export to CSV</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "excel",
						"text": "<i class='fa fa-file-excel-o bigger-110 green'></i> <span class='hidden'>Export to Excel</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "pdf",
						"text": "<i class='fa fa-file-pdf-o bigger-110 red'></i> <span class='hidden'>Export to PDF</span>",
						"className": "btn btn-white btn-primary btn-bold"
					  },
					  {
						"extend": "print",
						"text": "<i class='fa fa-print bigger-110 grey'></i> <span class='hidden'>Print</span>",
						"className": "btn btn-white btn-primary btn-bold",
						autoPrint: false,
						message: 'This print was produced using the Print button for DataTables'
					  }		  
					]
				} );
				myTable.buttons().container().appendTo( $('.tableTools-container') );
				
				//style the message box
				var defaultCopyAction = myTable.button(1).action();
				myTable.button(1).action(function (e, dt, button, config) {
					defaultCopyAction(e, dt, button, config);
					$('.dt-button-info').addClass('gritter-item-wrapper gritter-info gritter-center white');
				});
				
				
				var defaultColvisAction = myTable.button(0).action();
				myTable.button(0).action(function (e, dt, button, config) {
					
					defaultColvisAction(e, dt, button, config);
					
					
					if($('.dt-button-collection > .dropdown-menu').length == 0) {
						$('.dt-button-collection')
						.wrapInner('<ul class="dropdown-menu dropdown-light dropdown-caret dropdown-caret" />')
						.find('a').attr('href', '#').wrap("<li />")
					}
					$('.dt-button-collection').appendTo('.tableTools-container .dt-buttons')
				});
			
				////
			
				setTimeout(function() {
					$($('.tableTools-container')).find('a.dt-button').each(function() {
						var div = $(this).find(' > div').first();
						if(div.length == 1) div.tooltip({container: 'body', title: div.parent().text()});
						else $(this).tooltip({container: 'body', title: $(this).text()});
					});
				}, 500);
				
				
				
				
				
				myTable.on( 'select', function ( e, dt, type, index ) {
					if ( type === 'row' ) {
						$( myTable.row( index ).node() ).find('input:checkbox').prop('checked', true);
					}
				} );
				myTable.on( 'deselect', function ( e, dt, type, index ) {
					if ( type === 'row' ) {
						$( myTable.row( index ).node() ).find('input:checkbox').prop('checked', false);
					}
				} );
			
			
			
			
				/////////////////////////////////
				//table checkboxes
				$('th input[type=checkbox], td input[type=checkbox]').prop('checked', false);
				
				//select/deselect all rows according to table header checkbox
				$('#dynamic-table > thead > tr > th input[type=checkbox], #dynamic-table_wrapper input[type=checkbox]').eq(0).on('click', function(){
					var th_checked = this.checked;//checkbox inside "TH" table header
					
					$('#dynamic-table').find('tbody > tr').each(function(){
						var row = this;
						if(th_checked) myTable.row(row).select();
						else  myTable.row(row).deselect();
					});
				});
				
				//select/deselect a row when the checkbox is checked/unchecked
				$('#dynamic-table').on('click', 'td input[type=checkbox]' , function(){
					var row = $(this).closest('tr').get(0);
					if(!this.checked) myTable.row(row).deselect();
					else myTable.row(row).select();
				});
			
			
			
				$(document).on('click', '#dynamic-table .dropdown-toggle', function(e) {
					e.stopImmediatePropagation();
					e.stopPropagation();
					e.preventDefault();
				});
				
				
				
				//And for the first simple table, which doesn't have TableTools or dataTables
				//select/deselect all rows according to table header checkbox
				var active_class = 'active';
				$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
					var th_checked = this.checked;//checkbox inside "TH" table header
					
					$(this).closest('table').find('tbody > tr').each(function(){
						var row = this;
						if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
						else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
					});
				});
				
				//select/deselect a row when the checkbox is checked/unchecked
				$('#simple-table').on('click', 'td input[type=checkbox]' , function(){
					var $row = $(this).closest('tr');
					if(this.checked) $row.addClass(active_class);
					else $row.removeClass(active_class);
				});
			
				
			
				/********************************/
				//add tooltip for small view action buttons in dropdown menu
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				
				//tooltip placement on right or left
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					//var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			})
			
	/**
	 * 供应商助记码
	 */
	$("#purchaseform-suppliername").keyup(function(){
		var name = $(this).val();
	
		$.ajax({
			type:'post',
			url:"?r=purchase/supplier",
			data:{
				action:'supplierab',
				name:name
			},
			dataType:'html',
			success:function(msg){
				$("#purchaseform-supplierab").empty().val(msg)
			}
		});
	})
	
	$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
		_title: function(title) {
			var $title = this.options.title || '&nbsp;'
			if( ("title_html" in this.options) && this.options.title_html == true )
				title.html($title);
			else title.text($title);
		}
	}));
	/**
	 * 供应商查看
	 */
	function view(id){
		$.ajax({
			type:'post',
			url:'?r=purchase/supplierview',
			data:{id:id},
			dataType:'html',
			success:function(msg){
				$('#dialog-message').html(msg);
			}
		});
		var dialog = $( "#dialog-message" ).removeClass('hide').dialog({
			modal: true,
			width:'400',
			title: "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='ace-icon fa fa-check'></i>查看详情</h4></div>",
			title_html: true,
			buttons: [ 
				{
					text: "返回",
					"class" : "btn btn-primary btn-minier",
					click: function() {
						$( this ).dialog( "close" ); 
					} 
				}
			]
		});
	}


	/**
	 * 供应商列表修改
	 */
	function update(id){
		$.ajax({
			type:'post',
			url:'?r=purchase/supplierupdate',
			data:{
				id:id,
				action:'update'
			},
			dataType:'html',
			success:function(msg){
				$('#dialog-message').html(msg);
			}
		});

		var dialog = $( "#dialog-message" ).removeClass('hide').dialog({
			modal: true,
			width:'500',
			title: "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='ace-icon fa fa-check'></i>查看详情</h4></div>",
			title_html: true,
			buttons: [ 
				{
					text: "返回",
					"class" : "btn btn-primary btn-minier",
					click: function() {
						$( this ).dialog( "close" ); 
					} 
				}
			]
		});
	};
	
	
	/**
	 * 供应商列表单条删除
	 */
	 function supplierdelete(id){
			bootbox.setLocale("zh_CN");
			bootbox.confirm("是否确定删除?", function(result) {
				if(result) {
					$.ajax({
						type:"post",
						url :'?r=purchase/supplierdelete',
						data:{id:id},
						success:function(msg){
							if(msg !== "修改成功")
								alert(msg);
							else
								myTable.draw( false );
						}
					})
				}
			});
		}

	